Skip to content

Update zaptest.Logger to use t.Helper()#1512

Open
bts-bastion wants to merge 2 commits intouber-go:masterfrom
bts-bastion:zaptest-helper
Open

Update zaptest.Logger to use t.Helper()#1512
bts-bastion wants to merge 2 commits intouber-go:masterfrom
bts-bastion:zaptest-helper

Conversation

@bts-bastion
Copy link
Copy Markdown

This provided more meaningful logging location information.

This provided more meaningful logging location information.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Oct 3, 2025

CLA assistant check
All committers have signed the CLA.

Comment thread zaptest/testingt.go Outdated
Comment on lines +43 to +46

// Helper marks the calling function as a test helper function.
// When printing file and line information, that function will be skipped.
Helper()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't add methods to an interface as that's technically a breaking change

Instead, we can try to upcast the TestingT interface to see if it has a helper method, and use it if it exists.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks - understood. I've updated the PR to avoid the adjustment of the TestingT interface.

Using alternative approach from review comments.
Comment thread zaptest/logger.go
return nil
}

func (w TestingWriter) IsHelper() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of issues with this:

  • This method doesn't need to be exported
  • Calling tb.Helper() from inside of this method probably won't do anything for the caller Write method which I thought was the point. Can you include output verifying that this works as expected before/after this change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants